//
//  SearchWebViewController.m
//  CarFace
//
//  Created by dlios on 15-3-31.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "SearchWebViewController.h"
#import "UIButton+InitButton.h"
@interface SearchWebViewController ()<UIWebViewDelegate>
@property(nonatomic, retain)UIView * netView;
@property(nonatomic, retain)UIView *jumpView;
@end

@implementation SearchWebViewController
-(void)dealloc
{
    [_ipAddress release];
    [_netView release];
    [_jumpView release];
    [super dealloc];


}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.netView = [[UIView alloc]initWithFrame:self.view.bounds];
    [self.view addSubview:self.netView];
    [_netView release];
    //    self.aView.backgroundColor = [UIColor purpleColor];
    [self datahander];
    
    //  顶部实现
    CGFloat width = self.netView.frame.size.width;
//    CGFloat height = self.netView.frame.size.height;
    UIButton *returnButton = [UIButton buttonWithTitle:@"返回" frame:CGRectMake(0, 18, width / 4,30) target:self action:@selector(clickReturnButton:)];
    [returnButton setImage:[UIImage imageNamed:@"iconfont-fanhui.png"] forState:UIControlStateNormal];
    [returnButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.netView addSubview:returnButton];
    
    
//    UIButton *pageButton = [UIButton buttonWithTitle:@"1/40页" frame:CGRectMake(width - 80, height - 35, 60, 30) target:self action:@selector(clickPageButton:)];
//    [pageButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [self.netView addSubview:pageButton];
//    [self.view bringSubviewToFront:self.netView];
    
   
    
}


- (void)datahander
{
    CGFloat width = self.view.frame.size.width;
    CGFloat height = self.view.frame.size.height;
  
    NSString *strIp = self.ipAddress;
    NSURL *url = [NSURL URLWithString:strIp];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 50, width, height - 90)];
    webView.delegate = self;
    webView.scalesPageToFit = YES;
    [webView loadRequest:request];
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    [self.netView addSubview:webView];
    [webView release];
  
}

- (void)clickPageButton:(UIButton *)button
{
    
    self.jumpView = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height  * 2 / 3, self.view.frame.size.width, self.view.frame.size.height / 3)];
    [self.view addSubview:self.jumpView];
    self.jumpView.backgroundColor = [UIColor greenColor];
    
    UIButton *cancle = [UIButton buttonWithTitle:@"取消" frame:CGRectMake(5, 2, self.jumpView.frame.size.width / 6, self.jumpView.frame.size.height / 5) target:self action:@selector(clickCancleButtonAction:)];
    [self.jumpView addSubview:cancle];
    cancle.backgroundColor = [UIColor purpleColor];
    
    UIButton *ensure = [UIButton buttonWithTitle:@"确定" frame:CGRectMake(self.jumpView.frame.size.width - 2 - self.jumpView.frame.size.width / 6, 2, self.jumpView.frame.size.width / 6, self.jumpView.frame.size.height / 5) target:self action:@selector(clickEnsureButtonAction:)];
    [self.jumpView addSubview:ensure];
    ensure.backgroundColor = [UIColor purpleColor];
    
    [_jumpView release];
    NSLog(@"ddddddddd");
    
}



- (void)clickCancleButtonAction:(UIButton *)button
{
//  [self.view bringSubviewToFront:self.aView];
    self.netView.hidden = YES;
    NSLog(@"fff");
}

- (void)clickEnsureButtonAction:(UIButton *)button
{
    NSLog(@"ggkkk");
}


- (void)clickReturnButton:(UIButton *)button
{
    
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
    
}


- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
